<?php

/* OpenBIBLIO -- A library administration web interface
 * Copyright (C) 2002-2005 Frederic Descamps <lefred@tiscali.be>
 * Copyright (C) 2011-     Laurent Luyssen   <big.lol13@gmail.com>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 */
 
# priority of locale settings :
# 1 : From database config.language
# 2 : From locale parameter of POST request
# 3 : From locale parameter of GET request
# 4 : Default harcoded below to en_US


DEFINE("TEXT_DOMAIN", "openbiblio");

function localize($locale = '') {
	if (empty($locale))
		$locale = 'en_US';
	if (setlocale(LC_MESSAGES, $locale) !== false)
		return true;
	$locale .= ".utf8";
	if (setlocale(LC_MESSAGES, $locale) !== false)
		return true;
	else
		return false;
}


$locale = '';
if (isSet($_GET["locale"]))
	$locale = $_GET["locale"];
if (isSet($_POST["locale"]))
	$locale = $_POST["locale"];
if (empty($locale)) # selection of the default language from the database;
	$locale = get_language();
if (empty($locale))
	$locale = 'en_US';
	
if (localize($locale) == true) {
	putenv("LC_MESSAGES=$locale");
	putenv("LANGUAGE=$locale");
	bindtextdomain(TEXT_DOMAIN, "./locale");
	bind_textdomain_codeset(TEXT_DOMAIN, 'UTF-8');
	textdomain(TEXT_DOMAIN);
}
?>
